<?php
namespace Wx\Controller;
use Common\Controller\HomebaseController;

require_once './plugins/WebRTC/WebRTCSigApi.php';

class WebrtcController extends HomebaseController {

    private $sdkappid   = 1400180658;       //腾讯云云通信sdkappid

    public function get_user_sig()
    {
        $roomid = I('room_id'); // 房间号
        $userid = I('user_id'); // 用户id

        $api = new \WebRTCSigApi();

        //设置在腾讯云申请的sdkappid
        $api->setSdkAppid($this->sdkappid);

        //读取私钥的内容 PS:不要把私钥文件暴露到外网直接下载了哦
        $private = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'private_key');
        //设置私钥(签发usersig需要用到）
        $api->SetPrivateKey($private);

        //生成privateMapKey
        $privateMapKey = $api->genPrivateMapKey($userid, $roomid);

        //生成userSig
        $userSig = $api->genUserSig($userid);

        $ret = array(
            'privateMapKey' => $privateMapKey,
            'userSig'       => $userSig
        );
        echo json_encode($ret);
    }
}
